package homework.Thirty;

import org.omg.CORBA.FREE_MEM;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class EventTest  {
    public static void main(String[] args) {
        Frame frame=new Frame();
        frame.setSize(new Dimension(200,300));
        frame.setVisible(true);
        frame.setLayout(new BorderLayout());
        MyButton1 myButton1=new MyButton1("Right Button");
        frame.add("Center",myButton1);


    }
}

class MyButton1 extends Button{
    public MyButton1(String b){
        super(b);
        enableEvents(AWTEvent.ACTION_EVENT_MASK);
    }

    @Override
    public void processEvent(AWTEvent e){
        ActionEvent ae;
        String arg;
        if (e instanceof ActionEvent){
            ae=(ActionEvent)e;
            arg=ae.getActionCommand();
            if ("Left Button".equals(arg)){
                System.out.println("Press Left But ton");
                return;
            }
            else if ("Right Button".equals(arg)){
                System.out.println("Press Right Button");
                return;
            }

        }

        super.processEvent(e);
    }
}
